<?php

abstract class MCActiveRecord extends CActiveRecord
{
	public static function model($className = '')
	{
		//PHP 5 >= 5.3.0
		if (function_exists('get_called_class') && empty($className))
		{
			$className = get_called_class();
		}
		return parent::model($className);
	}
	
	public function tableName()
    {
        return '{{'.$this->_table.'}}';
    }
    
    public function primaryKey()
    {
    	return $this->_id;
    }
	
    /**
     * 分页方法
     * @param string $condition 附加条件
     * @param number $pageSize 每分显示行数
     * @param mixed $with 关联查询
     * @param string $pageVar	分页标签
     * @return array
     */
    public function pager($condition = '', $pageSize = 20, $with = false, $pageVar = 'p')
    {
    	$pages = '';
    	$models = '';
    	$criteria = new CDbCriteria($condition);
    	$count = $this->count($criteria);
    	if ($count > 0)
    	{
    		$pages = new CPagination($count);
    		$pages->pageVar = $pageVar;
    		$pages->pageSize = $pageSize;
    		//$pages->route = '/role/index';
    		$pages->applyLimit($criteria);
    		if ($with)
    		{
    			$this->with($with);
    		}
    		$models = $this->findAll($criteria);
    	}
    	return array('pages' => $pages, 'res' => $models);
    }
}